import axios from '@/utils/request'
// import store from '@/store'

// 登录请求接口
export const loginAPI = ({ username, password }) => {
  return axios({
    url: '/user/login',
    method: 'POST',
    data: {
      username,
      password
    }
  })
}

// 轮播图请求
export const imgAPI = () => {
  return axios({
    url: '/home/swiper'
  })
}

// 根据城市名称查询该城市信息
export const infoAPI = (name) => {
  return axios({
    url: '/area/info',
    method: 'GET',
    params: {
      name
    }
  })
}

// 根据条件查询房屋
export const houseAPI = (cityInfo) => {
  return axios({
    url: '/houses',
    params: cityInfo
  })
}

// 获取城市列表数据
export const cityAPI = () => {
  return axios({
    url: '/area/city',
    method: 'GET',
    params: {
      level: 1
    }
  })
}

// 查询热门城市
export const hotAPI = () => {
  return axios({
    url: '/area/hot',
    method: 'GET'
  })
}

// 获取子级城市列表
export const areaAPI = (id) => {
  return axios({
    url: '/area',
    params: {
      id
    }
  })
}

// 获取房屋查询条件
export const conditionAPI = (id) => {
  return axios({
    url: '/houses/condition',
    params: {
      id
    }
  })
}

// 获取租房小组
export const groupsAPI = (area) => {
  return axios({
    url: '/home/groups',
    params: {
      area
    }
  })
}

// 发布房屋所需的条件
export const paramsAPI = () => {
  return axios({
    url: '/houses/params'
  })
}

// 房屋图像上传
export const houseImgAPI = (form) => {
  return axios({
    url: '/houses/image',
    method: 'POST',
    data: form,
    headers: {
      authorization: 'multipart/form-data'
    }
  })
}

// 发布房源
export const userhouseAPI = (body) => {
  return axios({
    url: '/user/houses',
    method: 'POST',
    data: body
  })
}

// 查询房屋具体信息
export const housexiAPI = (id) => {
  return axios({
    url: `/houses/${id}`
  })
}

// 小区关键字查询
export const houseCommunityAPI = ({ name, id }) => {
  return axios({
    url: '/area/community',
    params: {
      name,
      id
    }
  })
}

// 获取用户的信息资料
export const userLoginmessage = ({ authorization }) => {
  return axios({
    url: '/user',
    method: 'GET',
    headers: {
      authorization: authorization
    }
  })
}

// 查询房源数据
export const houseMapAPI = ({ id }) => {
  return axios({
    url: '/area/map',
    params: {
      id
    }
  })
}

// 查看收藏列表
export const favoritesAPI = ({ authorization }) => {
  return axios({
    url: '/user/favorites',
    headers: {
      authorization
    }
  })
}

// 我的出租
export const houstTorentAPI = ({ authorization }) => {
  return axios({
    url: '/user/houses',
    headers: {
      authorization
    }
  })
}

// 添加收藏
export const addFavoritesAPI = ({ id }) => {
  return axios({
    url: `/user/favorites/${id}`,
    method: 'POST'
  })
}

// 删除收藏
export const delFavoritesAPI = ({ id }) => {
  return axios({
    url: `/user/favorites/${id}`,
    method: 'DELETE'
  })
}
